<?php

namespace app\admin\model;

class Bannermodel extends Commonmodel {

    protected $croomTable;

    public function __construct(array $data = [])
    {
        $this->table = 'zhjs_ad';
        $this->pk = 'id';
        parent::__construct($data);
        $this->catTable = 'zhjs_content_classify';
    }

    public function findAll($where = null, $pageParam = null, $num = 20){
        $whereData = [['a.is_delete' , '=', 1]];
        $paginate = ['list_rows'=>$num];

        if($where)  $whereData = array_merge($where, $whereData);
        if($pageParam = array_splice($pageParam, 1))  $paginate = array_merge($paginate, ['query'=>$pageParam]);

        $data = self::db()
            ->alias('a')
            ->leftJoin([$this->catTable=>'c'],'a.cid=c.id and c.is_delete and c.status = 1')
            ->field('a.id, a.title, a.status, a.img, a.create_date, c.name')
            ->where($whereData)
            ->order(['a.order'=>'desc', 'a.id'=>'desc'])
            ->paginate($paginate);

        if(!$data)  return false;

        $list['page'] = $data->render();
        $dataArr = $data->toArray();
        $list['data'] = $dataArr['data'];

        return $list;
    }

}

?>